import { Injector } from '@angular/core';
import { AppConsts } from '@shared/AppConsts';
import { LocalizationService } from '@abp/localization/localization.service';
import { PermissionCheckerService } from '@abp/auth/permission-checker.service';
import { FeatureCheckerService } from '@abp/features/feature-checker.service';
import { NotifyService } from '@abp/notify/notify.service';
import { SettingService } from '@abp/settings/setting.service';
import { MessageService } from '@abp/message/message.service';
import { AbpMultiTenancyService } from '@abp/multi-tenancy/abp-multi-tenancy.service';
import { AppSessionService } from '@shared/common/session/app-session.service';
import { NzMessageService, NzNotificationService } from 'ng-zorro-antd';

export abstract class AppComponentBase {
  localizationSourceName = AppConsts.localization.defaultLocalizationSourceName;

  localization: LocalizationService;
  permission: PermissionCheckerService;
  // feature: FeatureCheckerService;
  // notify: NotifyService;
  setting: SettingService;
  // message: MessageService;
  message: NzMessageService;
  notification:NzNotificationService;
  // multiTenancy: AbpMultiTenancyService;
  appSession: AppSessionService;
  serviceIpUrl: String;

  // ARCGIS MAP BASIC CONFIG
  /**
   * _zoom sets map zoom
   * _center sets map center
   * _basemap sets type of map
   */
  _zoom: number = 12;
  _center: any = [13.250435,-8.819191];
  _basemap: string = 'streets';

  constructor(injector: Injector) {
    this.localization = injector.get(LocalizationService);
    this.permission = injector.get(PermissionCheckerService);
    // this.feature = injector.get(FeatureCheckerService);
    // this.notify = injector.get(NotifyService);
    this.setting = injector.get(SettingService);
    this.message = injector.get(NzMessageService);
    this.notification = injector.get(NzNotificationService);
    // this.multiTenancy = injector.get(AbpMultiTenancyService);
    this.appSession = injector.get(AppSessionService);
    this.serviceIpUrl = "http://localhost:8081";
  }


  l(key: string, ...args: any[]): string {
    return this.ls(this.localizationSourceName, key, args);
  }

  ls(sourcename: string, key: string, ...args: any[]): string {
    let localizedText = this.localization.localize(key, sourcename);

    if (!localizedText) {
      localizedText = key;
    }

    if (!args || !args.length) {
      return localizedText;
    }

    args[0].unshift(localizedText);

    return abp.utils.formatString.apply(this, args[0]);
  }

  isGranted(permissionName: string): boolean {
    return this.permission.isGranted(permissionName);
  }

  isGrantedAny(...permissions: string[]): boolean {
    if (!permissions) {
      return false;
    }

    for (const permission of permissions) {
      if (this.isGranted(permission)) {
        return true;
      }
    }

    return false;
  }



}
